<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: DataLoader</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">DataLoader</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../files/lib/data_loader_rb.html">
                lib/data_loader.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000003">load_services</a>&nbsp;&nbsp;
      <a href="#M000002">load_users</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000003" class="method-detail">
        <a name="M000003"></a>

        <div class="method-heading">
          <a href="#M000003" class="method-signature">
          <span class="method-name">load_services</span><span class="method-args">(path)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000003-source">
<pre>
    <span class="ruby-comment cmt"># File lib/data_loader.rb, line 30</span>
30:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">load_services</span> <span class="ruby-identifier">path</span>
31:     <span class="ruby-identifier">log</span> = {<span class="ruby-identifier">:loaded</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>, <span class="ruby-identifier">:parse_fail</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>}
32:     <span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">path</span>, <span class="ruby-value str">'rb'</span>)
33:     
34:     <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">line</span> = <span class="ruby-identifier">f</span>.<span class="ruby-identifier">gets</span> <span class="ruby-keyword kw">do</span>
35:       <span class="ruby-identifier">line</span>.<span class="ruby-identifier">chomp!</span>
36:       <span class="ruby-identifier">fields</span> = <span class="ruby-identifier">line</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">'|'</span>)
37:       
38:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fields</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">6</span> <span class="ruby-keyword kw">then</span>
39:         <span class="ruby-identifier">ff_id</span> = <span class="ruby-identifier">parse_field</span>(<span class="ruby-identifier">fields</span>[<span class="ruby-value">0</span>])
40:         <span class="ruby-identifier">u</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find_by_ff_id</span>(<span class="ruby-identifier">ff_id</span>)
41:         
42:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">u</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">then</span>
43:           <span class="ruby-identifier">u</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">create</span>(<span class="ruby-identifier">:ff_id</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">ff_id</span>)
44:           <span class="ruby-identifier">log</span>[<span class="ruby-identifier">:users_created</span>] <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
45:         <span class="ruby-keyword kw">end</span>
46:         
47:         <span class="ruby-identifier">u</span>.<span class="ruby-identifier">services</span>.<span class="ruby-identifier">create</span>(<span class="ruby-identifier">:ff_id</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">parse_field</span>(<span class="ruby-identifier">fields</span>[<span class="ruby-value">1</span>]),
48:           <span class="ruby-identifier">:service_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">parse_field</span>(<span class="ruby-identifier">fields</span>[<span class="ruby-value">2</span>]),
49:           <span class="ruby-identifier">:service_url</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">parse_field</span>(<span class="ruby-identifier">fields</span>[<span class="ruby-value">3</span>]),
50:           <span class="ruby-identifier">:uername_on_service</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">parse_field</span>(<span class="ruby-identifier">fields</span>[<span class="ruby-value">4</span>]),
51:           <span class="ruby-identifier">:user_url_on_service</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">parse_field</span>(<span class="ruby-identifier">fields</span>[<span class="ruby-value">5</span>]))
52:         <span class="ruby-identifier">log</span>[<span class="ruby-identifier">:loaded</span>] <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
53:       <span class="ruby-keyword kw">else</span>
54:         <span class="ruby-identifier">log</span>[<span class="ruby-identifier">:parse_fail</span>] <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
55:       <span class="ruby-keyword kw">end</span>
56:     <span class="ruby-keyword kw">end</span>
57:     
58:     <span class="ruby-identifier">f</span>.<span class="ruby-identifier">close</span>
59:     <span class="ruby-identifier">log</span>
60:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000002" class="method-detail">
        <a name="M000002"></a>

        <div class="method-heading">
          <a href="#M000002" class="method-signature">
          <span class="method-name">load_users</span><span class="method-args">(path)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000002-source">
<pre>
    <span class="ruby-comment cmt"># File lib/data_loader.rb, line 6</span>
 6:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">load_users</span>(<span class="ruby-identifier">path</span>)
 7:     <span class="ruby-identifier">log</span> = {<span class="ruby-identifier">:loaded</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>, <span class="ruby-identifier">:parse_fail</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>, <span class="ruby-identifier">:users_created</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>}
 8:     <span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">path</span>, <span class="ruby-value str">'rb'</span>)
 9:     
10:     <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">line</span> = <span class="ruby-identifier">f</span>.<span class="ruby-identifier">gets</span> <span class="ruby-keyword kw">do</span>
11:       <span class="ruby-identifier">line</span>.<span class="ruby-identifier">chomp!</span>
12:       <span class="ruby-identifier">fields</span> = <span class="ruby-identifier">line</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">'|'</span>)
13:       
14:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fields</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">5</span> <span class="ruby-keyword kw">then</span>
15:         <span class="ruby-constant">User</span>.<span class="ruby-identifier">create</span>(<span class="ruby-identifier">:ff_id</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">parse_field</span>(<span class="ruby-identifier">fields</span>[<span class="ruby-value">0</span>]),
16:           <span class="ruby-identifier">:ff_type</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">parse_field</span>(<span class="ruby-identifier">fields</span>[<span class="ruby-value">1</span>]),
17:           <span class="ruby-identifier">:name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">parse_field</span>(<span class="ruby-identifier">fields</span>[<span class="ruby-value">2</span>]),
18:           <span class="ruby-identifier">:description</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">parse_field</span>(<span class="ruby-identifier">fields</span>[<span class="ruby-value">4</span>])
19:         )
20:         <span class="ruby-identifier">log</span>[<span class="ruby-identifier">:loaded</span>] <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
21:       <span class="ruby-keyword kw">else</span>
22:         <span class="ruby-identifier">log</span>[<span class="ruby-identifier">:parse_fail</span>] <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
23:       <span class="ruby-keyword kw">end</span>
24:     <span class="ruby-keyword kw">end</span>
25:     
26:     <span class="ruby-identifier">f</span>.<span class="ruby-identifier">close</span>
27:     <span class="ruby-identifier">log</span>
28:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>